function enableFields(fieldIds) {
    for (var i = 0; i < fieldIds.length; i++) {
        document.getElementById(fieldIds[i]).disabled = true;
    }
}
function disableFields(fieldIds) {
    for (var i = 0; i < fieldIds.length; i++) {
     /* if(document.getElementById(fieldIds[i]) == null){
            alert("disable " + fieldIds[i]);
        }*/
        document.getElementById(fieldIds[i]).disabled = true;
    }
}
function showFields(fieldIds) {
    for (var i = 0; i < fieldIds.length; i++) {
        //  alert("show " + fieldIds[i]);
        document.getElementById(fieldIds[i]).disabled = false;
    }
}
function numbersonly(e, decimal) {
    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;

    keychar = String.fromCharCode(key);
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        return true;
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;
    else if (decimal && (keychar == "."))
        return true;
    else
        return false;
}

function dateNumbersOnly(e, decimal) {
    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;

    keychar = String.fromCharCode(key);
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        return true;
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;
    else if (decimal && (keychar == "-"))
        return true;
    else
        return false;

}

$.validator.addMethod("isDateFormated", function validateDate(value) {
// regular expression to match required date format
    var re = /^\d{4}\-\d{1,2}\-\d{1,2}$/;
    if (value != '' && !value.match(re))
        return false;
    else return true;
},
        "Please enter a date in the format yyyy-mm-dd"
        );

function disablePaste(fieldIdList) {
    for (var i = 0; i < fieldIdList.length; i++) {
        var id = fieldIdList[i];
        $('#' + id).bind('cut copy paste', function (e) {
            e.preventDefault();
        });
    }
}

function checkDecimal() {
    var str = document.getElementById('annualIncome').value.toString();
    var temp = str.split('.');
    if (temp[0].size() < 17 && temp[1].size() < 2) {
        return true;
    }
    else return false;
}
//browser Back
function goBack() {
    window.history.back();
}

function resetIncome(){
        var x = $('#annualIncome').val().match(/,/g);
        if(x!=null){
            var y=x.length;
            while(y>0){
                $('#annualIncome').val($('#annualIncome').val().replace(",",""));
                y--;
            }
        }
        return true;
    }

/*function validateCurrency(event,e){
    //numbersonly(event,true);
    var n = document.getElementById(e).value.toString();
    var x = Number(n);
    alert(x);
    document.getElementById(e).value= convertCurrency(x);
    return true;
}

function convertCurrency(n) {
    return n.toFixed(2).replace(/./g, function(c, i, a) {
        return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
    });
} */

